<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<title>用户管理 - 用户编辑</title>
		<meta name="description" content="overview &amp; stats" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/bootstrap.min.css" />
		<link rel="stylesheet" href="${request.contextPath}/static/assets/font-awesome/4.2.0/css/font-awesome.min.css" />
		<!-- page specific plugin styles -->
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/jquery-ui.custom.min.css" />
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/jquery.gritter.min.css" />
		<!-- text fonts -->
		<link rel="stylesheet" href="${request.contextPath}/static/assets/fonts/fonts.googleapis.com.css" />
		<!-- BootstrapValidator -->
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/bootstrapValidator.min.css" />
		<!-- ace styles -->
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />
		<!-- ace settings handler -->
		<script src="${request.contextPath}/static/assets/js/ace-extra.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/jquery.2.1.1.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/bootstrap.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/jquery-ui.custom.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/jquery.ui.touch-punch.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/bootbox.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/jquery.gritter.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/spin.min.js"></script>
		<!-- ace scripts -->
		<script src="${request.contextPath}/static/assets/js/ace-elements.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/ace.min.js"></script>
		<!-- validator scripts -->
		<script src="${request.contextPath}/static/assets/js/bootstrapValidator.min.js"></script>
		<!-- user scripts -->
		<script src="${request.contextPath}/static/assets/js/user/base.js"></script>
	</head>

	<body class="no-skin" style="background-color: #FFF;">
		<div class="page-content">
			<div class="page-header">
				<h1>
					<!-- 用户管理
					<small>
						<i class="ace-icon fa fa-angle-double-right"></i> -->
						<#if user?? && user.id??>
						编辑用户
						<#else>
						新增用户
						</#if>
					<!-- </small> -->
				</h1>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<form id="platformForm" class="form-horizontal" role="form" action="${request.contextPath}/saveUser" method="POST">
						<input type="hidden" id="_csrf" name="${_csrf.parameterName}" value="${_csrf.token}"/>
						<input type="hidden" id="hiddenMd5" name="hiddenMd5" value="${user.password!}">
						<#if message??>
						<input type="hidden" id="message" name="message" value="${message}">
						</#if>
						<#if user?? && user.id??>
						<input type="hidden" id="id" name="id" value="${user.id}">
						<input type="hidden" id="oldPassword" name="oldPassword" value="${user.password!}">
						</#if>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 姓名 </label>
							<div class="col-sm-9">
								<input type="text" id="characterName" name="characterName" placeholder="姓名" value="${user.characterName!}" class="col-xs-10 col-sm-5">
							</div>
						</div>
						<div class="space-4"></div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 登录名 </label>
							<div class="col-sm-9">
								<input type="text" id="username" name="username" placeholder="登录名" value="${user.username!}" class="col-xs-10 col-sm-5" <#if user?? && user.id??>readonly='readonly'</#if>>
							</div>
						</div>
						<div class="space-4"></div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 密码 </label>
							<div class="col-sm-9">
								<input type="password" id="password" name="password"  placeholder="密码" value="${user.password!}" class="col-xs-10 col-sm-5">
							</div>
						</div>
						<div class="space-4"></div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 确认密码 </label>
							<div class="col-sm-9">
								<input type="password" id="rePassword" name="rePassword"  placeholder="再次输入密码" value="${user.password!}" class="col-xs-10 col-sm-5">
							</div>
						</div>
						<div class="space-4"></div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 电话 </label>
							<div class="col-sm-9">
								<input type="text" id="phone" name="phone" placeholder="电话号码" value="${user.phone!}" class="col-xs-10 col-sm-5">
							</div>
						</div>
						<div class="space-4"></div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 邮箱 </label>
							<div class="col-sm-9">
								<input type="text" id="email" name="email" placeholder="邮箱地址" value="${user.email!}" class="col-xs-10 col-sm-5">
							</div>
						</div>
						<div class="space-4"></div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 角色 </label>
							<div class="col-sm-9">
								<#list roles as role>
								<label class="inline" style="margin-top:7px;">
									<input name="roleIdList" type="checkbox" value="${role.id!}" class="ace" <#if user?? && user.roleIdList?seq_contains(role.id)>checked="checked"</#if> >
									<span class="lbl"> ${role.name!}</span>
								</label>
								</#list>
							</div>
						</div>
						<div class="space-4"></div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 备注 </label>
							<div class="col-sm-9">
								<input type="text" id="remarks" name="remarks" value="${user.remarks!}" class="col-xs-10 col-sm-5">
							</div>
						</div>
						<div class="space-4"></div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 是否启用 </label>
							<div class="col-sm-9">
								<label style="margin-top:7px;">
									<input id="isEnable" name="isEnable" class="ace ace-switch ace-switch-2" type="checkbox" <#if user?? && user.isEnable=1>checked="checked"</#if> >
									<span class="lbl"></span>
								</label>
							</div>
						</div>

						<div class="clearfix form-actions">
							<div class="col-md-offset-4 col-md-8">
								<button id="submitBtn" class="btn btn-info" type="button">
									<i class="ace-icon fa fa-check bigger-110"></i>
									保存
								</button>
							</div>
						</div>
					</form>
				</div><!-- /.col -->
			</div><!-- /.row -->
		</div>


		<!-- inline scripts related to this page -->
		<script type="text/javascript">
		$(document).ready(function(event) {
			
				var message = $('#message').val();
				if(message)
				{
					showMsg(message);
				}
				$('#submitBtn').on('click', function(){
					/* var telRule=new RegExp("(\d{3}-|\d{4}-)?(\d{8}|\d{7})");
					var emailRule=new RegExp("^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$");
					var telphone=$("#phone").val();
					var email=$("#email").val(); */
					var userid = $("#id").val();
					var name = $("#characterName").val();
					var loginName = $("#username").val();
					var password = $("#password").val();
					var rePassword = $("#rePassword").val();
					var result = "0";
					var message = "";
					if(userid==null || userid==""){
						$.ajax({
							url : '${request.contextPath}/checkUserName?username='+loginName,
							type : "GET",
							async: false,
							success:function(data) {
								if(data.sessionStatus==540){//异步请求session过期状态
									window.location.href="${request.contextPath}/login";
								}else{
									result = data.result;
									message=data.msg;
								}
							},
							error:function(data) {
							}
						});
					}
					
					//数据合法性校验
					if(result == "1")
					{
						showMsg(message);
						return;
					}
					else if(isEmpty(name)) {
						$("#characterName").focus();
						showMsg("姓名不能为空！");
						return;
					} else if(isEmpty(loginName)) {
						$("#username").focus();
						showMsg("登录名不能为空！");
						return;
					} else if(isEmpty(password)) {
						$("#password").focus();
						showMsg("密码不能为空！");
						return;
					} else if(isEmpty(rePassword)) {
						$("#rePassword").focus();
						showMsg("确认密码不能为空！");
						return;
					} else if(password != rePassword) {
						$("#rePassword").focus();
						showMsg("两次输入的密码不一致！");
						return;
					} 
					var role_value =[]; 
					$('input[name="roleIdList"]:checked').each(function(){ 
						role_value.push($(this).val()); 
					}); 
					if(role_value.length==0){
						showMsg("用户权限不能为空！");
						return;
					}
					$("#platformForm").submit();
				});
			});
		</script>
	</body>
</html>